!  Farallon Netopia PC Card PPP 56
!	Author:	Kris Kreutzman
!
!	Copyright:	 1991-1996 Apple Computer, Inc.	All Rights Reserved.
!
!	revision history:
!		v2.1	as shipped with the ARA 2.1
!		10/22/96 GRW	Modified for Netopia ISDN PC Card
!    	12/14/96 GRW Additional modifications for PC Card
!    	02/03/97 GRW Added higher speed connections
!		02/19/97 GRW Changed for PPP only
!
!  'mlts' resource info for this modem:
!    byte 1 == 01 -> modem HAS built-in error correction protocols
!    byte 2 == 01 -> modem HAS built-in data compression protocols
!    byte 3 == 40 -> max number of chars in varstr 7
!    byte 4 == 40 -> max number of chars in varstr 8
!    byte 5 == 40 -> max number of chars in varstr 9
!	
@ORIGINATE
@ANSWER
!
! ---- Initial modem setup ----
!
! Always set serial port to 57600
!	 - This invokes PC Card turbo mode if selected
! 
serreset 57600, 0, 8, 1
!
hsreset 0 0 0 0 0 0
settries 0
ifANSWER 2
!
! Get the modem's attention and configure for PPP
!   %A2=95 - Set to PPP
!   &W0 - Write profile 0
!   Z - restart the card
!
note "Configuring ISDN TA for PPP." 3
matchclr
matchstr 1 2 "OK\13\10"
write "AT%A2=95&W0Z\13"
matchread 100
jump 101
!
@LABEL 2
note "Checking signalling (D) Channel." 3
pause 10
!
@LABEL 3
matchclr
matchstr 1 4 "ON\13"
write "at>vdl\13"
matchread 30
inctries
iftries 60 103
pause 5
flush
jump 3
!
@LABEL 4
settries 0
!
@LABEL 5
!
! Setup the modem for the following:
!   The Netopia ISDN PC Card was set up by the ISDN
!       setup application so minimal setting is needed here.
!   E0 - Disable local echo
!   W0 - Report Connect only
!   V1 - Verbose responses
!
matchclr
matchstr 1 10   "OK\13\10"
matchstr 2 101 "ERROR\13\10"
write "ATE0W0V1\13"
matchread 30
inctries
iftries 3 101
!
! Reset the Modem on setup failure
!
DTRClear
pause 5
DTRSet
flush
jump 5
!
! Modem ready, wait for a call or originate a call
!
@LABEL 10
ifANSWER 32
!
!
! ---- Originating a call ----
!
!
! Varstring 6, dialing mode:
!    = 0, normal dialing
!    = 1, blind dialing
!    = 2, manual dialing
ifstr 6 17 "1"
ifstr 6 15 "2"
jump 19
!
@LABEL 15
! Display ASK dialog with message.  Goto label 107 if dialog canceled.
ASK 2 "Pick up the phone & dial ^1.  Hit OK when the phone rings, then hangup." 107
note "Manual dialing initiated" 3
! X1 to ignore dialtone & busy, D to dial, \^ generates data tone
write "ATX1DI^*\13"
jump 32
!
@LABEL 17
note "Dialing without tone" 3
matchclr
matchstr 1 19 "OK\13\10"
! X1 to ignore dialtone & busy
write "ATX1\13"
matchread 30
jump 101
!
!
@LABEL 19
! Display the full dialstring contained in Varstring 1
note "Dialing ^1" 3
!
! Varstrings 7, 8 and 9, contain dialstring fragments
!    Long phone numbers may need to be split into smaller groups
!    for the modem to use
!
! Varstring 3:  "p" for pulse & "t" for tone dialing
! Varstring 8 == blank (dialstring in varstring 7)
! Varstring 9 == blank (dialstring in varstrings 7 & 8)
! Otherwise (dialstring in varstrings 7, 8 & 9)
! \^ is added to the dialstring to force the modem to generate a data tone
ifstr 8 27 " "
ifstr 9 24 " "
!
!  Write dialstring in varstrings 7, 8 & 9
matchclr
matchstr 1 21 "OK\13\10"
write "ATDI^7;\13"
matchread 400
jump 101
!
@LABEL 21
matchclr
matchstr 1 22 "OK\13\10"
write "ATDI^8;\13"
matchread 400
jump 101
!
@LABEL 22
write "ATDI^9\13"
jump 32
!
!
@LABEL 24
!  Write dialstring in varstrings 7 & 8
matchclr
matchstr 1 25 "OK\13\10"
write "ATDI^7;\13"
matchread 400
jump 101
!
@LABEL 25
write "ATDI^8\13"
jump 32
!
@LABEL 27
!  Write dialstring in varstring 7
write "ATDI^7\13"
!
!    ---- Modem (TA) responses ----
!
@LABEL 32
matchclr
matchstr  1 81  "RING\13\10"
matchstr  2 102 "NO DIALTONE\13\10"
matchstr  3 103 "NO CARRIER"
matchstr  4 103 "ERROR\13\10"
matchstr  5 104 "BUSY\13\10"
matchstr  6 105 "NO ANSWER\13\10"
matchstr  7 33  "CARRIER"
matchstr  8 41  "PROTOCOL: PPPC"
matchstr  9 42  "PROTOCOL: V120"
matchstr 10 50  "CONNECT"
matchread 700
ifANSWER 32
jump 101
!
!  Parse the Carrier response
!
@LABEL 33
matchclr
matchstr 1 34 "57600"
matchstr 2 35 "64000"
matchstr 3 36 "115200"
matchstr 4 37 "128000"
matchread 30
jump 32
!
! -- Carrier rates --
!
@LABEL 34
note "Using 1B @ 56Kbps." 3
jump 32
!
@LABEL 35
note "Using 1B @ 64Kbps." 3
jump 32
!
@LABEL 36
note "Using 2B @ 115Kbps." 3
jump 32
!
@LABEL 37
note "Using 2B @ 128Kbps." 3
jump 32
!
@LABEL 41
note "Protocol is PPP" 3
jump 32
!
@LABEL 42
note "Protocol is V.120" 3
jump 32
!
!  Parse the Connect response
!
@LABEL 50
matchclr
matchstr 1 51 "57600"
matchstr 2 52 "64000"
matchstr 3 53 "115200"
matchstr 4 54 "128000"
matchstr 5 55 "230400"
matchstr 6 56 "256000"
matchstr 7 57 "358400"
matchstr 8 58 "460800"
matchstr 9 59 "512000"
matchread 30
jump 69
!
! -- Connection rates --
!  CommunicatingAt informs ARA of the raw modem to modem
!  connection speed.
!
@LABEL 51
note "Communicating at 57600 bps." 3
CommunicatingAt 57600
jump 70
!
@LABEL 52
note "Communicating at 64000 bps." 3
CommunicatingAt 64000
jump 70
!
@LABEL 53
note "Communicating at 115200 bps." 3
CommunicatingAt 115200
jump 70
!
@LABEL 54
note "Communicating at 128000 bps." 3
CommunicatingAt 128000
jump 70
!
@LABEL 55
note "Communicating at 230400 bps." 3
CommunicatingAt 230400
jump 70
!
@LABEL 56
note "Communicating at 256000 bps." 3
CommunicatingAt 256000
jump 70
!
@LABEL 57
note "Communicating at 358400 bps." 3
CommunicatingAt 358400
jump 70
!
@LABEL 58
note "Communicating at 460800 bps." 3
CommunicatingAt 460800
jump 70
!
@LABEL 59
note "Communicating at 512000 bps." 3
CommunicatingAt 512000
jump 70
!
@LABEL 69
note "Communicating at unknown speed." 3
CommunicatingAt 115200
!
!
! -- Normal exit after "CONNECT" --
!
!  This modem has been setup to do CTS handshaking,
!  and we assume that a CTS handshaking cable is being used.
!
@LABEL 70
! Turn on CTS handshaking.
HSReset 0 1 0 0 0 0
!
ifANSWER 71
pause 30
@LABEL 71
exit 0
!
!
! ---- Answer calls ----
!
!	A RING result from the modem and in ANSWERING mode
!	claims the serial port and answering the phone
!
@LABEL 81
ifORIGINATE 32
userhook 1
note "Answering phone..." 2
write "ATA\13"
jump 32
!
!
! ---- Hang up and reset modem ----
!
@HANGUP
@LABEL 90
settries 0
HSReset 0 0 0 0 0 0
!
@LABEL 92
!  Escape from data to command mode
matchclr
matchstr 1 96 "OK\13\10"
write "+++"
matchread 20
!
@LABEL 94
! Force a hangup
matchclr
matchstr 1 98 "NO CARRIER\13\10"
matchstr 2 98 "OK\13\10"
matchstr 3 98 "ERROR\13\10"
matchstr 4 98 "0\13\10"
write "ATH\13"
matchread 30
! 
! Try to get control of the modem by toggling DTR
DTRClear
pause 5
DTRSet
flush
!
! Try the hangup sequence three times otherwise declare and error
inctries
iftries 3 101
jump 92
!
@LABEL 96
! Pause between data and command mode
pause 50
jump 94
!
!
@LABEL 98
! Recall the factory settings
pause 15
matchclr
matchstr 1 99 "OK\13\10"
write "AT&F\13"
matchread 30
jump 101
!
@LABEL 99
exit 0
!
! ---- Error messages -----
!
! Modem Not Responding
@LABEL 101
exit -6019
!
! No Dial Tone
@LABEL 102
exit -6020
!
! No Carrier or Error
@LABEL 103
exit -6021
!
! Busy
@LABEL 104
exit -6022
!
! No Answer
@LABEL 105
exit -6023
!
! User Cancellation
@LABEL 107
exit -6008
